import { CacheModule, MiddlewareConsumer, Module, NestMiddleware, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ArtColumnModule } from './modules/artColumn/artColumn.module';
import { UserModule } from './modules/user/user.module';
import { RoleModule } from './modules/role/role.module';
import { ArtSortModule } from './modules/artSort/artSort.module';
import { ArtModule } from './modules/art/art.module';
import { ImgSortModule } from './modules/imgSort/imgSort.module';
import { ImgModule } from './modules/img/img.module';
import { MenuModule } from './modules/menu/menu.module';
import { DictModule } from './modules/dict/dict.module';
import { LogModule } from './modules/log/log.module';
import { HomeModule } from './modules/home/home.module';
import { AuthModule } from './modules/auth/auth.module';
import { SysConfigModule } from './modules/sysConfig/sysConfig.module';
import {mysqlConfig} from "@/utils/config"
import { MsgModule } from './modules/common/msg/msg.module';
import { extname, join } from 'path';
import {ServeStaticModule} from "@nestjs/serve-static";

let mysql =  TypeOrmModule.forRoot(mysqlConfig);
// ImgModule,ArtModule,DictModule
@Module({
  //nestjs设置静态资源访问
  //ip+端口号/static/图片名称.png(jpg)
  //https://juejin.cn/post/7186683352467832869
  imports: [ServeStaticModule.forRoot({
    rootPath: join(__dirname, '..', 'public/uploads'),
    serveRoot: '/static',
  }),mysql,HomeModule,MsgModule,ArtColumnModule,SysConfigModule, UserModule, RoleModule,DictModule,ImgModule,ArtModule, MenuModule, ImgSortModule, ArtSortModule, LogModule, AuthModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): any {
    // consumer.apply(ReqMiddleware).forRoutes("/")
  }
}